<template>
    <div>
        <h1>人员列表</h1>
        <h3 style="color: red">上方组件的求和为：{{ sum }}</h3>
        <input type="text" placeholder="请输入名字" v-model="name">
        <button @click="add">添加</button>
        <button @click="searchAndAdd(name)">搜索并添加</button>
        <ul>
            <li v-for="p in persons" :key="p.id">{{ p.name }}</li>
        </ul>
    </div>
</template>

<script>
import {mapState, mapMutations, mapActions} from "vuex";
import {nanoid} from "nanoid";

export default {
    name: "Persion",
    computed: {
        ...mapState('personConfig', ['persons']),
        ...mapState('countConfig', ['sum'])
    },
    data() {
        return {
            name: ''
        }
    },
    methods: {
        add() {
            const p = {id: nanoid(), name: this.name}
            this.name = '';
            // this.$store.commit('personConfig/ADD_PERSON', p);
            this.addPerson(p)
            console.log(p)
        },
        ...mapMutations('personConfig', {addPerson: 'ADD_PERSON'}),
        ...mapActions('personConfig', {searchAndAdd: 'addPersonFromGitHub'})
    }
}
</script>

<style scoped>

</style>